# deliverance pyquery rules

#<!--<append href="/dspace/xmlui/handle/123456789/1"
#content="#ds-body"
#theme="children:#apkn-external-content"
#nocontent="ignore"/>-->

from pyquery import  PyQuery as pq
import re

re_country = '/apex/country-folders/[a-zA-Z\-]+[/]?$'

def match_country_folder(req, resp, headers, *args):
	'''
	match a request for country folder in apex
	'''
	match = False
	if len(re.findall(re_country, req.path_info)) == 1:
		match = False
	return match

def load_dspace_content(content, theme, resource_fetcher, log):
	pass

def fix_links(content, theme, resource_fetcher, log):
	'''
	Fixes broken DSpace links after including
	content from DSpace into Plone
	'''
	links = theme("a[href^='/xmlui']")
	for link in links:
		link_target = "/dspace" + link.get('href')
		pq(link).attr('href', link_target)
	
def showme(l):
	print pq(l)
		
